package cn.com.miao.lynx.common.core.model

import cn.hutool.core.util.ObjectUtil

/**
 * PageParam
 * @title: PageParam
 * @description:
 * @author: dengmiao
 * @create: 2019-12-23 17:13
 **/
class PageParam() {

    var pageNo: Int? = 0
    var pageSize: Int? = 10
    var sort: String? = null
    var order: String? = null

    constructor(pageNo: Int?,
                pageSize: Int?,
                sort: String?,
                order: String?) : this() {
        this.pageNo = pageNo
        this.pageSize = pageSize
        this.sort = sort
        this.order = order
    }

    companion object {

        @JvmStatic
        fun of(): PageParam {
            return of(null)
        }

        @JvmStatic
        fun of(pageNo: Int?): PageParam {
            return of(pageNo, null)
        }

        @JvmStatic
        fun of(pageNo: Int?, pageSize: Int?): PageParam {
            return of(pageNo, pageSize, null)
        }

        @JvmStatic
        fun of(pageNo: Int?, pageSize: Int?, sort: String?): PageParam {
            return of(pageNo, pageSize, sort, null)
        }

        @JvmStatic
        fun of(pageNo: Int?, pageSize: Int?, sort: String?, order: String?): PageParam {
            return PageParam(if (ObjectUtil.isNull(pageNo)) {pageNo} else {0},
                    if (ObjectUtil.isNull(pageSize)) {pageSize} else {0},
                    sort, order)
        }
    }
}
